
*****************************************************************
** NOTE: For this data file we have de-identified the data     **
** and added noise to all of the variables in order to protect **
** the identities of the survey respondents.  For that reason, ** 
** the variables will not exactly replicate what is found in   **
** the published article. If you are interested in getting the ** 
** de-identified data for research purposes, please contact    ** 
** the authors.    											   **
*****************************************************************


use "De-identified Data.dta", clear

*******************	
******Figure 2*****
*******************	
	#delimit;
		twoway
		(scatter perc_bluecollar blue_collar if party=="D", msymbol(circle) mcolor(blue%25) mlwidth(none))
		(scatter perc_bluecollar blue_collar if party=="R", msymbol(diamond) mcolor(red%25) mlwidth(none)) 
		(lowess perc_bluecollar blue_collar if party=="R", lwidth(thick) lcolor(red)) 
		(lowess perc_bluecollar blue_collar if party=="D", lwidth(thick) lpattern(longdash) lcolor(blue)) 
		(line perc_poverty perc_poverty, sort lpattern(solid) lcolor(black)), 
		xlabel(0(20)100, grid) ylabel(0(20)100, grid) legend(off) xtitle("Census Estimate of % Blue Collar Workers in District") ytitle("Legislators' Estimate of" " % Blue Collar Workers in District") 
		plotregion(style(none)) plotregion(fcolor(white)) graphregion(fcolor(white)) name(bluecollar`sample');
		graph export "Partisan_Bluecollar_alt_`sample'.png", replace;
	#delimit cr

	
*******************	
******Figure 3*****
*******************
	#delimit;
		twoway
		(scatter perc_poverty cen_poverty_rate_families if party=="D", msymbol(circle) mcolor(blue%25) mlwidth(none))  
		(scatter perc_poverty cen_poverty_rate_families if party=="R" & [perc_poverty>40 | cen_poverty_rate_families>40], msymbol(diamond) mcolor(red%25) mlwidth(none))  
		(scatter perc_poverty cen_poverty_rate_families if party=="R" & perc_poverty<=40 & cen_poverty_rate_families<=40, msymbol(diamond) mcolor(red%10) mlwidth(none))  
		(lowess perc_poverty cen_poverty_rate_families if party=="R", lwidth(thick) lcolor(red)) 
		(lowess perc_poverty cen_poverty_rate_families if party=="D", lwidth(thick) lpattern(longdash) lcolor(blue%90)) 
		(line perc_poverty perc_poverty, sort lpattern(solid) lcolor(black)), 
		xlabel(0(20)100, grid) ylabel(0(20)100, grid) legend(off) xtitle("Census Estimate of % in Poverty in District") ytitle("Legislators' Estimate" "of % in Poverty in District") 
		plotregion(style(none)) plotregion(fcolor(white)) graphregion(fcolor(white)) name(poverty`sample');
		//graph export "Partisan_Poverty_alt_`sample'.png", replace;
	#delimit cr

	#delimit;
		twoway
		(scatter perc_latino cen_perc_latino if party=="D", msymbol(circle) mcolor(blue%25) mlwidth(none)) 
		(scatter perc_latino cen_perc_latino if party=="R" & [perc_latino>=10 | cen_perc_latino>=10], msymbol(diamond) mcolor(red%25) mlwidth(none)) 
		(scatter perc_latino cen_perc_latino if party=="R" & perc_latino<10 & cen_perc_latino<10, msymbol(diamond) mcolor(red%3) mlwidth(none))  
		(lowess perc_latino cen_perc_latino if party=="R", lwidth(thick) lcolor(red))
		(lowess perc_latino cen_perc_latino if party=="D", lwidth(thick) lpattern(longdash) lcolor(blue%90)) 
		(line perc_poverty perc_poverty, sort lpattern(solid) lcolor(black)), 	
		xlabel(0(20)100, grid) ylabel(0(20)100, grid) legend(off) xtitle("Census Estimate of % Latino in District") ytitle("Legislators' Estimate of" "% Latino in District") 
		plotregion(style(none)) plotregion(fcolor(white)) graphregion(fcolor(white)) name(latino`sample');
		//graph export "Partisan_Latino_alt_`sample'.png", replace;
	#delimit cr

	#delimit;
		twoway
		(scatter perc_black cen_perc_black if party=="D", msymbol(circle) mcolor(blue%25) mlwidth(none)) 
		(scatter perc_black cen_perc_black if party=="R" & [perc_black >10 | cen_perc_black>10], msymbol(diamond) mcolor(red%25) mlwidth(none)) 
		(scatter perc_black cen_perc_black if party=="R" & perc_black <=10 & cen_perc_black<=10, msymbol(diamond) mcolor(red%3) mlwidth(none))
		(lowess perc_black cen_perc_black if party=="R", lwidth(thick) lcolor(red)) 
		(lowess perc_black cen_perc_black if party=="D", lwidth(thick) lpattern(longdash) lcolor(blue%90)) 
		(line perc_poverty perc_poverty, sort lpattern(solid) lcolor(black)), 
		xlabel(0(20)100, grid) ylabel(0(20)100, grid) legend(off) xtitle("Census Estimate of % Black in District") ytitle("Legislators' Estimate of" "% Black in District") 
		plotregion(style(none)) plotregion(fcolor(white)) graphregion(fcolor(white)) name(black`sample');
		//graph export "Partisan_Black_alt_`sample'.png", replace;
	#delimit cr

	#delimit;
		twoway
		(scatter perc_homeowners owner_occupied if party=="D", msymbol(circle) mcolor(blue%25) mlwidth(none))
		(scatter perc_homeowners owner_occupied if party=="R" & perc_homeowners!=50 & perc_homeowners!=60 & perc_homeowners!=70 & perc_homeowners!=80, msymbol(diamond) mcolor(red%25) mlwidth(none))
		(scatter perc_homeowners owner_occupied if party=="R" & perc_homeowners==50 & perc_homeowners==60 & perc_homeowners==70 & perc_homeowners==80, msymbol(diamond) mcolor(red%5) mlwidth(none)) 
		(lowess perc_homeowners owner_occupied if party=="R", lwidth(thick) lcolor(red)) 
		(lowess perc_homeowners owner_occupied if party=="D", lwidth(thick) lpattern(longdash) lcolor(blue%90)) 
		(line perc_poverty perc_poverty, sort lpattern(solid) lcolor(black)), 
		xlabel(0(20)100, grid) ylabel(0(20)100, grid) legend(off) xtitle("Census Estimate of % Homeowners in District") ytitle("Legislators' Estimate of" "% Homeowners in District")
		plotregion(style(none)) plotregion(fcolor(white)) graphregion(fcolor(white)) name(home`sample');
		//graph export "Partisan_homeowners_alt_`sample'.png", replace;
	#delimit cr

	gr combine latino`sample' black`sample' poverty`sample' home`sample' , plotregion(style(none)) plotregion(fcolor(white)) graphregion(fcolor(white))
		graph export "Partisan_Lat-Bla-Pov-Hom_`sample'.png", replace
	

*******************	
******Table 1******
*******************
		local count=1
		foreach dv in diff_bluecollar diff_latino diff_black diff_poverty diff_homeowners {		
			reg `dv' democrat independent latino black tenure pop10K traveltime_dist squire_2003 close_election mrp_estimate 
				if `count'== 1 outreg2 using "Directional_Diff_main", ctitle(`dv') dec(2) alpha(0.05) symbol(*) label word se replace
				else outreg2 using "Directional_Diff_main", ctitle(`dv') dec(2) alpha(0.05) symbol(*) label word se append

			local count=`count'+1
			}

***********************
******IN APPENDIX******
***********************
			
	** Table A2. SUMMARY STATS 
		qui reg diff_poverty democrat independent latino black tenure pop10K squire_2003 close_election mrp_estimate 
				tabstat diff_bluecollar diff_latino diff_black diff_poverty diff_homeowners perc_bluecollar perc_latino perc_black perc_poverty perc_homeowner abs_dblue abs_dlat abs_dblack abs_dpo abs_dhome democrat independent latino black tenure pop10K traveltime_dist squire_2003 length_session staff_percapita  close_election mrp_estimate pres_2008 cen_bluecollar cen_latino cen_black cen_poverty cen_homeowner if e(sample), stat(count mean sd min p25 median p75 max) col(stat)
	
	** Table A3. Results w/out distance variable
		local count=1
		foreach dv in diff_bluecollar diff_latino diff_black diff_poverty diff_homeowners {		
			reg `dv' democrat independent latino black tenure pop10K squire_2003 close_election mrp_estimate 
				if `count'== 1 outreg2 using "Directional_Diff_main-no-distance", ctitle(`dv') dec(2) alpha(0.05) symbol(*) label word se replace
				else outreg2 using "Directional_Diff_main-no-distance", ctitle(`dv') dec(2) alpha(0.05) symbol(*) label word se append
			local count=`count'+1
			}

	** Table A4. Alternative Leg. Professionalism
		local count=1
		foreach dv in diff_bluecollar diff_latino diff_black diff_poverty diff_homeowners {		
			reg `dv' democrat independent latino black tenure pop10K traveltime_dist length_session staff_percapita close_election mrp_estimate 
				if `count'== 1 outreg2 using "Directional_Diff_alt-leg-prof", ctitle(`dv') dec(2) alpha(0.05) symbol(*) label word se replace
				else outreg2 using "Directional_Diff_alt-leg-prof", ctitle(`dv') dec(2) alpha(0.05) symbol(*) label word se append

			local count=`count'+1
			}
			
	** Table A5. State-chamber fixed effects
		xtset fe_st_ch
		local count=1
		foreach dv in diff_bluecollar diff_latino diff_black diff_poverty diff_homeowners {		
			xtreg `dv' democrat independent latino black tenure  pop10K close_election mrp_estimate , fe vce(robust)
				if `count'== 1 outreg2 using "Directional_Diff_fe", ctitle(`dv') dec(2) alpha(0.05) symbol(*) label word se replace
				else outreg2 using "Directional_Diff_fe", ctitle(`dv') dec(2) alpha(0.05) symbol(*) label word se append
			local count=`count'+1
			}
		
	**Table A6. Presidential Vote Share
		local count=1
		foreach dv in diff_bluecollar diff_latino diff_black diff_poverty diff_homeowners {		
			reg `dv' democrat independent latino black tenure pop10K  squire_2003 close_election pres_2008 
				if `count'== 1 outreg2 using "Directional_Diff_pres-vote", ctitle(`dv') dec(2) alpha(0.05) symbol(*) label word se replace
				else outreg2 using "Directional_Diff_pres-vote", ctitle(`dv') dec(2) alpha(0.05) symbol(*) label word se append

			local count=`count'+1
			}

	** Table A7. DV=Absolute value
		local count=1
		foreach dv in abs_dblue abs_dlat abs_dblack abs_dpo abs_dhome  {		
			reg `dv' democrat independent latino black tenure pop10K traveltime_dist squire_2003 close_election mrp_estimate 
				if `count'== 1 outreg2 using "Absolute_Diff_main", ctitle(`dv') dec(2) alpha(0.05) symbol(*) label word se replace
				else outreg2 using "Absolute_Diff_main", ctitle(`dv') dec(2) alpha(0.05) symbol(*) label word se append
			local count=`count'+1
			}		
	
	** Table A8. DV = Legislator's Perceptions
		local count=1
		foreach dv in bluecollar latino black poverty homeowners {	
			reg perc_`dv' democrat independent latino black tenure pop10K traveltime_dist squire_2003 close_election mrp_estimate cen_`dv' 
				if `count'== 1 outreg2 using "Perception-as-DV_main", ctitle(`dv') dec(2) alpha(0.05) symbol(*) label word se replace
				else outreg2 using "Perception-as-DV_main", ctitle(`dv') dec(2) alpha(0.05) symbol(*) label word se append
			local count=`count'+1
			}				
			
	** Table A9 + Figure A4. DV = Interactions with party			
		reg perc_bluecollar i.democrat##c.cen_bluecollar independent latino black tenure pop10K traveltime_dist squire_2003 close_election mrp_estimate 
		outreg2 using "predicted_outcomes", ctitle("Blue Collar") dec(2) label word se replace			
		margins, at(cen_bluecollar=(10(5)70)) over(democrat)
		marginsplot, addplot(line diagonal diagonal) name(blu, replace) scheme(s1color) title("")
		graph export "Predict_Partisan_Blue.png", replace
		
		reg perc_latino i.democrat c.cen_latino i.democrat##c.cen_latino independent latino black tenure pop10K traveltime_dist squire_2003 close_election mrp_estimate 
		outreg2 using "predicted_outcomes", ctitle("Latino") dec(2) label word se append		
		margins, at(cen_latino=(0(5)85)) over(democrat) 
		marginsplot, addplot(line diagonal diagonal) name(lat, replace) scheme(s1color) title("")
		graph export "Predict_Partisan_Latino.png", replace

		reg perc_black i.democrat##c.cen_black independent latino black tenure pop10K traveltime_dist squire_2003 close_election mrp_estimate 
		outreg2 using "predicted_outcomes", ctitle("Black") dec(2) label word se append			
		margins, at(cen_black=(0(5)95)) over(democrat) 
		marginsplot, addplot(line diagonal diagonal) name(bla, replace) scheme(s1color) title("")
		graph export "Predict_Partisan_Black.png", replace

		reg perc_poverty i.democrat##c.cen_poverty independent latino black tenure pop10K traveltime_dist squire_2003 close_election mrp_estimate 
		outreg2 using "predicted_outcomes", ctitle("Poverty") dec(2) label word se append		
		margins,  at(cen_poverty=(0(5)40)) over(democrat)
		marginsplot, addplot(line diagonal diagonal) name(pov, replace) scheme(s1color) title("")
		graph export "Predict_Partisan_Poverty.png", replace

		reg perc_homeowners i.democrat##c.cen_homeowners independent latino black tenure pop10K traveltime_dist squire_2003 close_election mrp_estimate 
		outreg2 using "predicted_outcomes", ctitle("Homeowners") dec(2) label word se append
		margins, at(cen_homeowners=(15(5)90)) over(democrat) 
		marginsplot, addplot(line diagonal diagonal) name(hom, replace) scheme(s1color) title("")
		graph export "Predict_Partisan_Home.png", replace
		
	** Table A10. Version of main results where all estimates are in the  model with a dummy for each demographic being estimated
		preserve
		use dataset_long.dta, clear
			
		reg absolutediff democrat independent dum_bluecollar dum_black dum_poverty dum_homeowners latino black tenure pop10K traveltime_dist squire_2003 close_election mrp_estimate, vce(cluster leg_id)	
		outreg2 using "Absolute_Diff_all-characteristics", ctitle(`dv') dec(2) alpha(0.05) symbol(*) label word se replace

		restore

/* Figures A5 and A6 */

cd "~/Dropbox/Butler-Dynes/Discounting Electoral Connection/Analysis/Results/"

cd "C:/Users/Adam/Documents/Dropbox/0 PROJECTS/Butler-Dynes/Discounting Electoral Connection/Analysis/Results/"

/*Figure A5. Voters*/
twoway(scatter perc_black voters_black if party=="R", msymbol(none) mlabcolor(red) mlabsize(vsmall) mlabel(rep_label)) (scatter perc_black voters_black if party=="D", msymbol(none) mlabel(dem_label) mlabcolor(blue) mlabsize(vsmall)) (lfit perc_black voters_black if party=="D", lwidth(thick) lpattern(dash) lcolor(blue)) (lfit perc_black voters_black if party=="R", lwidth(thick) lcolor(red)) (line perc_poverty perc_poverty, sort lpattern(dash) lcolor(black)), xlabel(0(20)100) legend(off) xtitle(Census Estimate of Blacks in District) ytitle("Legislators' Estimate of" "Blacks in District") plotregion(style(none)) plotregion(fcolor(white)) graphregion(fcolor(white)) saving(Results/black, replace)

twoway(scatter perc_bluecollar voters_bluecollar if party=="R", msymbol(none) mlabcolor(red) mlabsize(vsmall) mlabel(rep_label)) (scatter perc_bluecollar voters_bluecollar if party=="D", msymbol(none) mlabel(dem_label) mlabcolor(blue) mlabsize(vsmall)) (lfit perc_bluecollar voters_bluecollar if party=="D", lwidth(thick) lpattern(dash) lcolor(blue)) (lfit perc_bluecollar voters_bluecollar if party=="R", lwidth(thick) lcolor(red)) (line perc_poverty perc_poverty, sort lpattern(dash) lcolor(black)), xlabel(0(20)100) legend(off) xtitle(Census Estimate of Blue Collar Workers in District) ytitle("Legislators' Estimate of" "Blue Collar Workers in District") plotregion(style(none)) plotregion(fcolor(white)) graphregion(fcolor(white)) saving(Results/bluecollar, replace)

twoway(scatter perc_poverty voters_poverty if party=="R", msymbol(none) mlabcolor(red) mlabsize(vsmall) mlabel(rep_label)) (scatter perc_poverty voters_poverty if party=="D", msymbol(none) mlabel(dem_label) mlabcolor(blue) mlabsize(vsmall)) (lfit perc_poverty voters_poverty if party=="D", lwidth(thick) lpattern(dash) lcolor(blue)) (lfit perc_poverty voters_poverty if party=="R", lwidth(thick) lcolor(red)) (line perc_poverty perc_poverty, sort lpattern(dash) lcolor(black)), xlabel(0(20)100) legend(off) xtitle(Census Estimate of Poverty Rate) ytitle("Legislators' Estimate" "of Poverty Rate") plotregion(style(none)) plotregion(fcolor(white)) graphregion(fcolor(white)) saving(Results/poverty, replace)

twoway(scatter perc_latino voters_latino if party=="R", msymbol(none) mlabcolor(red) mlabsize(vsmall) mlabel(rep_label)) (scatter perc_latino voters_latino if party=="D", msymbol(none) mlabel(dem_label) mlabcolor(blue) mlabsize(vsmall)) (lfit perc_latino voters_latino if party=="D", lwidth(thick) lpattern(dash) lcolor(blue)) (lfit perc_latino voters_latino if party=="R", lwidth(thick) lcolor(red)) (line perc_poverty perc_poverty, sort lpattern(dash) lcolor(black)), xlabel(0(20)100) legend(off) xtitle(Census Estimate of Latinos in District) ytitle("Legislators' Estimate of" "Latinos in District") plotregion(style(none)) plotregion(fcolor(white)) graphregion(fcolor(white)) saving(Results/latino, replace)

	gr combine Results/latino.gph Results/black.gph Results/poverty.gph Results/bluecollar.gph, plotregion(style(none)) plotregion(fcolor(white)) graphregion(fcolor(white))
		graph export "know_district_voters.png", replace


/*Figure A6. Registrants*/
twoway(scatter perc_black registrants_black if party=="R", msymbol(none) mlabcolor(red) mlabsize(vsmall) mlabel(rep_label)) (scatter perc_black registrants_black if party=="D", msymbol(none) mlabel(dem_label) mlabcolor(blue) mlabsize(vsmall)) (lfit perc_black registrants_black if party=="D", lwidth(thick) lpattern(dash) lcolor(blue)) (lfit perc_black registrants_black if party=="R", lwidth(thick) lcolor(red)) (line perc_poverty perc_poverty, sort lpattern(dash) lcolor(black)), xlabel(0(20)100) legend(off) xtitle(Census Estimate of Blacks in District) ytitle("Legislators' Estimate of" "Blacks in District") plotregion(style(none)) plotregion(fcolor(white)) graphregion(fcolor(white)) saving(Results/black, replace)

twoway(scatter perc_bluecollar registrants_bluecollar if party=="R", msymbol(none) mlabcolor(red) mlabsize(vsmall) mlabel(rep_label)) (scatter perc_bluecollar registrants_bluecollar if party=="D", msymbol(none) mlabel(dem_label) mlabcolor(blue) mlabsize(vsmall)) (lfit perc_bluecollar registrants_bluecollar if party=="D", lwidth(thick) lpattern(dash) lcolor(blue)) (lfit perc_bluecollar registrants_bluecollar if party=="R", lwidth(thick) lcolor(red)) (line perc_poverty perc_poverty, sort lpattern(dash) lcolor(black)), xlabel(0(20)100) legend(off) xtitle(Census Estimate of Blue Collar Workers in District) ytitle("Legislators' Estimate of" "Blue Collar Workers in District") plotregion(style(none)) plotregion(fcolor(white)) graphregion(fcolor(white)) saving(Results/bluecollar, replace)

twoway(scatter perc_poverty registrants_poverty if party=="R", msymbol(none) mlabcolor(red) mlabsize(vsmall) mlabel(rep_label)) (scatter perc_poverty registrants_poverty if party=="D", msymbol(none) mlabel(dem_label) mlabcolor(blue) mlabsize(vsmall)) (lfit perc_poverty registrants_poverty if party=="D", lwidth(thick) lpattern(dash) lcolor(blue)) (lfit perc_poverty registrants_poverty if party=="R", lwidth(thick) lcolor(red)) (line perc_poverty perc_poverty, sort lpattern(dash) lcolor(black)), xlabel(0(20)100) legend(off) xtitle(Census Estimate of Poverty Rate) ytitle("Legislators' Estimate" "of Poverty Rate") plotregion(style(none)) plotregion(fcolor(white)) graphregion(fcolor(white)) saving(Results/poverty, replace)

twoway(scatter perc_latino registrants_latino if party=="R", msymbol(none) mlabcolor(red) mlabsize(vsmall) mlabel(rep_label)) (scatter perc_latino registrants_latino if party=="D", msymbol(none) mlabel(dem_label) mlabcolor(blue) mlabsize(vsmall)) (lfit perc_latino registrants_latino if party=="D", lwidth(thick) lpattern(dash) lcolor(blue)) (lfit perc_latino registrants_latino if party=="R", lwidth(thick) lcolor(red)) (line perc_poverty perc_poverty, sort lpattern(dash) lcolor(black)), xlabel(0(20)100) legend(off) xtitle(Census Estimate of Latinos in District) ytitle("Legislators' Estimate of" "Latinos in District") plotregion(style(none)) plotregion(fcolor(white)) graphregion(fcolor(white)) saving(Results/latino, replace)

	gr combine Results/latino.gph Results/black.gph Results/poverty.gph Results/bluecollar.gph, plotregion(style(none)) plotregion(fcolor(white)) graphregion(fcolor(white))
	graph export "know_district_registrants.png", replace

	
